package com.mly.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mly.service.UserService;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import orm.base.Ex.BaseControllerEx;
import orm.config.UnAuth;

import java.lang.reflect.Method;
import java.util.Map;


/**
 * 示例Controller
 *
 * @author 26061
 */
@Controller
@Scope("prototype")
@RequestMapping("user")
public class UserController extends BaseControllerEx {

    @Autowired
    UserService userService;

    @Override
    protected void init() {
        super.init(userService);
    }


    @UnAuth
    @RequestMapping(value = "/doLogin",method = RequestMethod.POST)
    public JSONObject doLogin(@RequestParam Map map) throws Exception{
       return userService.login(map,session);
    }

    /**
     * 跳转首页
     * @return
     * @throws Exception
     */
    @UnAuth
    @RequestMapping(value = "/login_page", method = RequestMethod.GET)
    public ModelAndView login_page() throws Exception {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("admin/login_page");
        return mv;
    }

    /**
     * 获取用户信息
     * @param map
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/doGetUserInfo", method = RequestMethod.POST)
    public JSONObject doGetUserInfo(@RequestParam Map map) throws Exception{
        return this.codeData(session.getAttribute("user-" + map.get("token").toString()));
    }

}

